import java.net.*;
import java.io.*;
import java.util.*;

import voip.Session;
import voip.SIPProperty;

public class SIPSpeaker
{
	public static SIPProperty sipProperty;
	
	public static void getArgument(String filename, String sip_uri, String http_addr)
	{
		sipProperty = new SIPProperty(filename, sip_uri, http_addr);		
		sipProperty.run(filename);
	}

	public static void main(String[] args)
	{
		int i = 0;
		String filename="";
		String sip_uri="";
		String http_bind_address="";

		if(args.length == 0)
		{
			// Default SIPSpeaker process (No arguments)
			Session sip_session = new Session();
			sip_session.run();
		}
		else if(args.length > 0)
		{
			// Read configuration file.
			while (i < args.length) 
			{
				// For debugging
				//System.out.println("args[" +i + "] :" + args[i]);
				if (args[i].equals("-c")) 
				{
					if(i+1 == args.length)
					{
						System.out.println("[Error] No input filename.");
						System.exit(0);
					}
					else
						filename = args[i + 1];				           
	            }
				
				else if(args[i].equals("-user"))
				{
					// sip_uri
					if(i+1 == args.length)
					{
						System.out.println("[Error] No user infomation.");
						System.exit(0);					
					}
					else
						sip_uri = args[i+1];
				}
				else if(args[i].equals("-http"))
				{
					if(i+1 == args.length)
					{
						System.out.println("[Error] No http bind address.");
						System.exit(0);					
					}
					else
						http_bind_address = args[i+1];
				}
				i++;
			}
			//SIPSpeaker.getArgument(filename, sip_uri, http_bind_address);
			
			// SIP Session starts
			Session sip_session = new Session(filename, sip_uri, http_bind_address);
			sip_session.run();

		}		// End of else
	}			// End of main
}